/**
 * Created by Administrator on 2017/9/8.
 */
define(function (require) {
    function execute() {
        var editCourseA = document.getElementById("edit-course");
        var courseIntroduceContentP = document.getElementById("course-introduce-content");
        var $ = require("jquery");
        require("jquery.cookie");
        var type = $.cookie("type");
        var userHandler = new require("userHandler");
        var checkInDom = document.getElementById('check-in');

        if (type === "student"){
            userHandler = new userHandler.StudentHandler();
            // 签到
            checkInDom.addEventListener('click',function () {
                if (this.classList.contains('done')) return;
                var that = this;
                userHandler.checkIn($.cookie('courseId'),function () {
                    that.classList.add('done');
                    that.innerHTML = '已签到'
                },function () {
                    alert('签到失败')
                })
            });
            editCourseA.style.display = "none";
        }else {
            userHandler = new userHandler.TeacherHandler();
            checkInDom.style.display = 'none';
            editCourseA.addEventListener("click",function () {
                // 弹窗
                require("popups").createEditCourseIntroducePopup();
            });
        }

        userHandler.getCourse($.cookie("courseId"),function (data) {
            courseIntroduceContentP.innerText = data.introduce;
        });

    }


    return{
        execute:execute
    }
})